// Application of Signal
// Created by Administrator on 2025/6/20.
//

#include <iostream>
using namespace std;

void signalHandle(int signum) {
    cout << "Interrupt signal: " << signum << " received. " << endl;
    exit(signum);
}

// linux system effective
int main(int argc, char *argv[]) {
    // statement signal handle
    // press ctrl + c to stop
    signal(SIGINT, signalHandle);
    // while (1) {
    //     cout << "Going to sleep……" << endl;
    //     _sleep(1000);
    // }

    // auto
    int i = 0;
    while (++i) {
        cout << "Going to sleep……" << endl;
        if (i == 5) {
            // auto call signalHandle
            raise(SIGINT);
        }
        _sleep(1000);
    }

    return 0;
}
